package com.hy.z.controller;


import com.hy.z.utils.TreeNode;
import com.hy.z.dto.UserBean;
import com.hy.z.result.Result;
import com.hy.z.service.ResourcesService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Fhy
 * @since 2021-01-14
 */
@RestController
@RequestMapping("/resources")
public class ResourcesController {
    @Autowired
    private ResourcesService resourcesService;

    /**
     * 根据身份查询菜单信息
     * @return
     */
    @RequestMapping("/queryUserResources")
    public Result queryMenus() throws Exception {
        Subject subject = SecurityUtils.getSubject();
        UserBean userLoginParam = (UserBean)subject.getPrincipal();
        List<TreeNode> treeNodes = resourcesService.queryMenusByUserId(userLoginParam);
        return Result.success(treeNodes);
    }
    /**
     * 获取所有菜单信息
     */
    @RequestMapping("/queryAllResources")
    public Result queryAllMenus(){
        List<TreeNode> treeNodes = resourcesService.queryAllMenus();
        return Result.success(treeNodes);
    }



}

